import { createApp } from 'vue';
import { createPinia } from 'pinia';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faFolder, faFile } from '@fortawesome/free-solid-svg-icons';
import App from './App.vue';
import router from './router';
import axios from 'axios';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import uploader from 'vue-simple-uploader';
import 'vue-simple-uploader/dist/style.css';


// 将图标添加到FontAwesome库
library.add(faFolder, faFile);

// 配置axios请求拦截器 (关键部分)
axios.interceptors.request.use(config => {
  // 从sessionStorage获取token
  const token = sessionStorage.getItem('token');
  // 如果token存在，添加到请求头
  if (token) {
    config.headers.Authorization = token;
  }
  return config;
}, error => {
  return Promise.reject(error);
});

// 创建Vue应用
const app = createApp(App);

// 全局注册axios以便在组件中使用
app.config.globalProperties.$axios = axios;
app.use(uploader);
// 注册FontAwesome图标组件
app.component('font-awesome-icon', FontAwesomeIcon);

// 使用Pinia
app.use(createPinia());
const pinia = createPinia()
app.use(pinia)

// 使用ElementPlus
app.use(ElementPlus);



// 使用路由
app.use(router);

// 挂载应用
app.mount('#app');
